/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: MENG
 * Date: 2022-07-09
 * Time: 20:50
 */
import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 35b379
 * Date: 2022-07-08
 * Time: 16:58
 */
public class MyStack {
    public int[] elem;
    public int usedSize;
    public static final int DEFAULT_CAPACITY = 10;

    public MyStack() {
        this.elem = new int[DEFAULT_CAPACITY];
    }

    public void push(int val){
        if(isFull()){
            elem = Arrays.copyOf(elem,elem.length*2);
        }
        elem[usedSize] = val;
        usedSize++;
    }

    /**
     * 判断 当前栈是否是满的
     * @return
     */
    private boolean isFull(){
        if(usedSize == elem.length){
            return true;
        }
        return false;
    }

    /**
     * 是否为空
     * @return
     */
    private boolean isEmpty(){
        return usedSize == 0;
    }

    public int pop(){
        if(isEmpty()){
            throw new EmptyStackException("栈是空栈");
        }
        int oldValue = elem[usedSize-1];
        usedSize--;
        return usedSize;
    }
/*    public void pop(){
        if(isEmpty()){
            throw new EmptyStackException("栈是空栈");
        }
        usedSize--;
    }*/

    public int peek(){
        if(isEmpty()){
            throw new EmptyStackException("栈是空栈");
        }
        return elem[usedSize-1];
    }

    public int getUsedSize(){
        return usedSize;
    }


}